<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/header.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<button type="button" class="mui-btn mui-btn-outlined mui-pull-right" id="btn_search" style="color: white;">搜索</button>
			<span class="mui-title title-color" style="text-align: left;margin-top: 2px;">添加朋友</span>
		</header>

		<div class="mui-content">
			<div class="mui-input-row">
				<input id="text_username" type="text" class="mui-input-speech mui-input-clear" placeholder="雨信账号">
			</div>
		</div>

		<script src="../../js/mui.min.js"></script>
		<script src="../../js/app.js"></script>
		<script type="text/javascript">
			mui.init()

			mui.plusReady(function() {
				var user = app.getUserGlobalInfo();

				var text_username = document.getElementById("text_username");

				// 提交事件，搜索朋友
				var btn_search = document.getElementById("btn_search");
				btn_search.addEventListener("tap", function() {

					var account = text_username.value;
					var params = {
						userId: user.id,
						account: account
					};
					plus.nativeUI.showWaiting("请稍后...");
					mui.ajax(app.serverUrl + "/user/search", {
						data: params,
						dataType: 'json', //服务器返回json格式数据
						type: 'get', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						success: function(res) {
							//服务器返回响应
							plus.nativeUI.closeWaiting();
							if (res.code == 0) {
								mui.openWindow({
									url: "friend-detail.html",
									id: "friend-detail.html",
									styles: {},
									extras: {
										requestFriend: res.data
									}
								});

							} else {
								app.showToast(res.msg, "error");
							}
						},
						error: function(xhr, type, errorThrown) {
							app.showToast(type, "error"); //异常处理；
						}
					});
				});

			});
		</script>

	</body>

</html>
